/*
 *所有关于Part_out_mfj_view类的业务代码应在此处编写
*可使用repository.调用常用方法，获取EF/Dapper等信息
*如果需要事务请使用repository.DbContextBeginTransaction
*也可使用DBServerProvider.手动获取数据库相关信息
*用户信息、权限、角色等使用UserContext.Current操作
*Part_out_mfj_viewService对增、删、改查、导入、导出、审核业务代码扩展参照ServiceFunFilter
*/
using VOL.Core.BaseProvider;
using VOL.Core.Extensions.AutofacManager;
using VOL.Entity.DomainModels;
using System.Linq;
using VOL.Core.Utilities;
using System.Linq.Expressions;
using VOL.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.AspNetCore.Http;
using MyErp.IRepositories;
using System.Collections.Generic;
using System;
using VOL.Core.DBManager;
using VOL.Core.ManageUser;

namespace MyErp.Services
{
    public partial class Part_out_mfj_viewService
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
        private readonly IPart_out_mfj_viewRepository _repository;//访问数据库

        [ActivatorUtilitiesConstructor]
        public Part_out_mfj_viewService(
            IPart_out_mfj_viewRepository dbRepository,
            IHttpContextAccessor httpContextAccessor
            )
        : base(dbRepository)
        {
            _httpContextAccessor = httpContextAccessor;
            _repository = dbRepository;
            //多租户会用到这init代码，其他情况可以不用
            //base.Init(dbRepository);
        }
        public override WebResponseContent Update(SaveModel saveModel)
        {
            WebResponseContent webResponse = new WebResponseContent();
            //sqlerver dblink到oracle执行update时需要用到openquery否则效率会非常慢，修改查询都是用openquery，可以提示运行效率
            //下面的实例绕开SQLServer事务，直接执行openquery的update的SQL语句
            UpdateOnExecuting = (Part_out_mfj_view order, object addList, object updateList, List<object> delKeys) =>
            {
                Console.WriteLine(order.TI_SCM_SAP_PARTOUT_ID);
                decimal ls_id = order.TI_SCM_SAP_PARTOUT_ID;
                string po_no = order.po_no;
                string po_line_no = order.po_line_no;
                Console.WriteLine(po_no);
                Console.WriteLine(po_line_no);
                string xgren = UserContext.Current.GetUserInfo(UserContext.Current.UserId).UserTrueName;
                string ddren = xgren;
                string ddtime = DateTime.Now.ToString("yyyyMMddHHmmss");
                string xdtime = ddtime;
                DBServerProvider.SqlDapper.ExcuteNonQuery("delete view_TI_SCM_SAP_PARTOUT_SAMPLE WHERE ti_scm_sap_partout_id=@ls_id", new { ls_id });
                DBServerProvider.SqlDapper.ExcuteNonQuery("insert into view_TI_SCM_SAP_PARTOUT_SAMPLE(ti_scm_sap_partout_id,po_no,po_line_no,UPDATE_BY,CREATE_BY,CREATE_DATE,UPDATE_DATE) values(@ls_id,@po_no,@po_line_no,@xgren,@xgren,@ddtime,@ddtime)", new { ls_id, po_no, po_line_no, xgren, ddren, ddtime, xdtime });
                //_repository.Update(order,true);
                webResponse.Code = "-1";//-1表示不执行后面的update，测试强制返回
                //webResponse.Message = "";
                return webResponse.OK("修改成功！");
            };
            return base.Update(saveModel);
        }
    }
}
